//
// Test class to test ChartView class
//
package SOEN_Phase_3;
import java.util.ArrayList;
import SOEN_Phase_3.ChartView;
import SOEN_Phase_3.Task;
import junit.framework.*;

public class ChartViewTest extends SwingTestCase {
    
    // Global variables
    private ChartView emptyChart;
    private ChartView taskChart;
    private ArrayList<Task> tasks;
    private static Task task1, task2, task3;

    
    public ChartViewTest() {
    }

    public static void setUpClass() throws Exception
    {
    }

    public static void tearDownClass() throws Exception 
    {
    }
    
    
     /**
     * Following method initialize two objects of type ChartView.
     * It also assert that the constructor works properly by creating
     * an empty chart and a chart that contains tasks.
     */
    @Override
    public void setUp ()  throws Exception
    {
        // Create an empty chart
        this.emptyChart = new ChartView(new Object[0]);
        
        // Check if the emptyChart JFrame is created
        assertTrue("Chart is created",this.emptyChart.isEnabled());
        
        // create a chart with tasks
        this.tasks = new ArrayList<Task>();
        task1 = new Task(1, 500, "Task 1", "Assignee 1", 101, 50, false, new ArrayList<Task>(), new ArrayList<Task>());
        task2 = new Task(2, 1000, "Task 2", "Assignee 2", 102, 100, false, new ArrayList<Task>(), new ArrayList<Task>());
        this.tasks.add(task1);
        this.tasks.add(task2);
        this.taskChart = new ChartView(tasks.toArray());
        
        // Check if the taskChart JFrame is created
        assertTrue("Chart is created",this.taskChart.isEnabled());
    }

    /**
     * Test of setShow method, of class ChartView.
     */
    
    public void testSetShow() throws Exception
    {        
        System.out.println("setShow");
        boolean x = true;
        boolean y = false;
            
        // Check if the emptyChart windows is not shown yet
        assertFalse("Chart is not visible",this.emptyChart.isVisible()); 
        
        // Set the emptyChart window to be shown
        this.emptyChart.setShow(x);
        // Check if the emptyChart windows is shown now
        assertTrue("Chart is visible",this.emptyChart.isVisible());
        
        // Set the emptyChart window to be not shown
        this.emptyChart.setShow(y);
        // Check if the emptyChart windows is not shown now
        assertFalse("Chart is visible",this.emptyChart.isVisible());
        

        // Check if the taskChart windows is not shown yet
        assertFalse("Chart is not visible",this.taskChart.isVisible()); 
        
        // Set the taskChart window to be shown
        this.taskChart.setShow(x);
        // Check if the taskChart windows is shown now
        assertTrue("Chart is visible",this.taskChart.isVisible());
        
        // Set the taskChart window to be not shown
        this.taskChart.setShow(y);
        // Check if the taskChart windows is not shown now
        assertFalse("Chart is visible",this.taskChart.isVisible());
    }

    /**
     * Test of chartUpdate method, of class ChartView.
     */
    
    public void testChartUpdate() {
        System.out.println("chartUpdate");
        
        // Create new task and added to the tasks array
        task3 = new Task(3, 2000, "Task 3", "Assignee 3", 103, 200, false, new ArrayList<Task>(), new ArrayList<Task>());
        this.tasks.add(task3);
        
        // Update the chart view
        this.taskChart.chartUpdate(tasks.toArray());

    }
}
